home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / machack / Hacks96 / BootingGallery.sit / Booting Gallery / Booting Gallery (source) / Sources / INIT Sources / BootingGalleryINIT.cpp next >
C/C++ Source or Header  |  1996-06-22  |  2KB  |  117 lines

  1. #include "DuckGame.h"
  2. #include <setupa4.h>
  3. #include <A4Stuff.h>
  4. #include <new.h>
  5. #include "blitter.h"
  6. #include "GWorldUtils.h"
  7. #include "StAllowDraw.h"
  8. #include <patches.h>
  9. #include "BlasteroidsGame.h"
  10.  
  11. static CSpriteGame*        gGame = NULL;
  12. pascal void InitGame();
  13.  
  14. void*    operator new (size_t size)
  15. {
  16.     return NewPtrSys(size);
  17. }
  18.  
  19. void    operator delete(void* obj)
  20. {
  21.     if(obj != NULL){
  22.         DisposePtr((Ptr)obj);
  23.     }
  24. }
  25.  
  26. typedef pascal void (*SystemTaskProc)();
  27. static long    gOldSystemTask;
  28.  
  29. static pascal void newSystemTask()
  30. {
  31.     EnterCallback();
  32.     
  33.     if(LMGetCurApRefNum() > 0){
  34.         if(gGame != NULL){
  35.             delete gGame;
  36.             gGame = NULL;
  37.         }
  38.     }
  39.     
  40.     (*(SystemTaskProc)gOldSystemTask)();
  41.  
  42.     ExitCallback();
  43. }
  44.  
  45. pascal void InitGame()
  46. {
  47. //    EnterCodeResource();
  48.     
  49.  
  50.     THz        saveZone = GetZone();
  51.     SetZone(SystemZone());
  52.     StAllowDraw            allowDraw;
  53.     
  54.     PrepareCallback();
  55.     gOldSystemTask = PatchTrap(_SystemTask,(long)newSystemTask);
  56. //    Handle    h = Get1IndResource('INIT',1);
  57. //    if(h != NULL){
  58. //        DetachResource(h);
  59.         
  60.         if (*((long*)0x178) != 0)
  61.             gGame = new CDuckGame;
  62.         else
  63.             gGame = new CBlasteroidsGame;
  64.         OSErr    err = gGame->Initialize();
  65.         if(err == noErr){
  66.         //    GWorldPtr        gWorld;
  67.         //    RgnHandle        mask;
  68.             
  69.         //    err = NewCIconGWorld(128,&gWorld,&mask);
  70.         //    if(err == noErr){
  71.         //        HLock((Handle)mask);
  72.         //        gGame->IntroduceExtensionIcon(gWorld,mask);
  73.                 gGame->StartGame();    
  74.         //    }
  75.         }
  76. //    }    
  77.     
  78.     SetZone(saveZone);
  79. //    ExitCodeResource();
  80. }
  81.  
  82. pascal void Blit(short iconID)
  83. {
  84.     gGame->StopGame();
  85.  
  86.     StAllowDraw            allowDraw;
  87.     StSaveGWorld        saveGWorld;
  88.     OSErr                err = noErr;
  89.     THz                    saveZone = GetZone();
  90.     Rect                bounds = {0,0,32,32};
  91.     GWorldPtr            newGWorld;
  92.     RgnHandle            newMask;
  93.     short                jbTempVBLMask;
  94.     
  95.     SetZone(SystemZone());
  96.     jbTempVBLMask = *(short *)0x160;
  97.     *(short *)0x160 |= 0x4000;
  98.  
  99.     ObscureCursor();
  100.     
  101.     err = NewLockedGWorld(&newGWorld,0,&bounds,NULL,NULL,0);
  102.     if(err == noErr){
  103.         SetGWorld(newGWorld,NULL);
  104.         PlotIconID(&bounds, 0, 0, iconID);
  105.         newMask = NewRgn();
  106.         IconIDToRgn(newMask,&bounds,0,iconID);
  107.         HLock((Handle)newMask);
  108.         
  109.         gGame->IntroduceExtensionIcon(newGWorld,newMask);
  110.     }
  111.     
  112.     *(short *)0x160 = jbTempVBLMask;
  113.     SetZone(saveZone);
  114.     gGame->StartGame();
  115. }
  116.  
  117.